// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#include "stdafx.h"

#pragma once

namespace HandBanana { namespace Core
{
    /// <summary>
    /// 
    /// </summary>
    public ref class Engine abstract sealed
    {
    public:

        /// <summary>
        /// The amount of time which must elapse before one tick of the game timer.
        /// </summary>
        static const float TicksPerSecond = 30.0f;
        static const float SecondsPerTick = 1.0f/TicksPerSecond;  // Thirty ticks per second

    // Constructor
    public:

        static Engine(void);

    // Public Methods
    public:

        /// <summary>
        /// 
        /// </summary>
        static Renderer^ GetRenderer(void);

        /// <summary>
        /// 
        /// </summary>
        static World^ GetWorld(void);

        /// <summary>
        /// 
        /// </summary>
        static void Initialize(Window^ argWindow);

        /// <summary>
        /// 
        /// </summary>
        static void Start(void);

        /// <summary>
        /// 
        /// </summary>
        static void Stop(void);


    // Private Methods
    private:

        /// <summary>
        /// The Engine's Main Loop
        /// </summary>
        static void Run(void);

        /// <summary>
        /// 
        /// </summary>
        static void Load(void);

        /// <summary>
        ///
        /// </summary>
        static void Update(void);

        /// <summary>
        ///
        /// </summary>
        static void Render(void);

        static void WindowKillFocus(Object^ argSender, EventArgs^ e);
        static void WindowMinimized(Object^ argSender, EventArgs^ e);
        static void WindowRestored(Object^ argSender, EventArgs^ e);
        static void WindowSetFocus(Object^ argSender, EventArgs^ e);


    // Private Data Members
    private:
        // Static Logger for this Class
        static NLog::Logger^                        smLogger = NLog::LogManager::GetCurrentClassLogger();

        // Engine State
        static Renderer^                            smRenderer;
        static Thread^                              smEngineThread;
        static Thread^                              smLoadThread;
        static Input^                               smInput;
        static Boolean                              smStallRendering;
        static Boolean                              smRunning;
        static Boolean                              smLoading;
        static Timer^                               smTimer;

        // View State
        static Coordinates::Rectangle               smWorldView;
        static Coordinates::Rectangle               smUIView;

        // Game State
        static World^                               smWorld;
        static Player^                              smPlayer;
        static ParticleSystem<SmokeParticle^>^      smSmokeParticleSystem;
        static ParticleSystem<FireParticle^>^       smFireParticleSystem;
        static ParticleSystem<AuraParticle^>^       smAuraParticleSystem;

        // UI State
        static LoadingBar^                          smLoadingBar;
        static UI^                                  smUserInterface;

        // Events
        static EventHandler^                        smWindowKillFocus;
        static EventHandler^                        smWindowMinimized;
        static EventHandler^                        smWindowRestored;
        static EventHandler^                        smWindowSetFocus;
        static SizedEventHandler^                   smWindowSized;

        // Window
        static Window^                              smMainWindow;

    public:
        static Boolean              QuitFlag;

    };
} }